<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Exaster 配置</title>
    <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css">
    <link rel="stylesheet" href="https://open.wwsg18.com/openres/editormd/css/editormd.css" />
</head>

<body>

    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">主页编辑</li>
            <li>更多工具</li>
            <li>静态绑定</li>
            <li>捐赠作者</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">

                <!-- <blockquote class="layui-elem-quote layui-quote-nm">
                    当本插件接管主页后，将渲染 "<a href="http://editor.md.ipandao.com/" target="_blank">MarkDown</a>" 当前内容！
                </blockquote> -->


                <div id="index-editor">
                    <textarea style="display:none;">{{MarkDown}}</textarea>
                </div>

            </div>
            <div class="layui-tab-item">

                <div class="layui-container">
                    <form class="layui-form layui-form-pane" action="">

                        <div class="layui-form-item" pane>
                            <label class="layui-form-label" title="是否开放信息反馈功能">信息反馈</label>
                            <div class="layui-input-block">
                                <select lay-filter="feedback-api" id="feedback-select"></select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">主页渲染</label>
                            <div class="layui-input-inline" style="width: 20%;">
                                <input type="text" readonly class="layui-input" id="now-idxp" value="当前接管权：框架本体">
                            </div>
                            <button style="float: left;" type="button" class="layui-btn" id="getIdxp">发送接管请求</button>
                        </div>

                    </form>
                </div>

            </div>
            <div class="layui-tab-item">
                <!-- 静态文件路径绑定 -->

                <blockquote class="layui-elem-quote">本功能可使您将静态文件目录绑定至框架！</blockquote>

                <div class="layui-container">
                    <div id="binded">
                        <div id="binded-tpl" style="display: none;">
                            <form class="layui-form" action="" id="lye-_domain_">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">静态绑定</label>
                                    <div class="layui-input-inline" style="width: 25%;">
                                        <input type="text" name="domapass" required lay-verify="required"
                                            placeholder="静态访问路径" value="_domain_" autocomplete="off"
                                            class="layui-input">
                                    </div>
                                    <div class="layui-input-inline" style="width: 45%;">
                                        <input type="text" name="localpass" required lay-verify="required"
                                            placeholder="本地文件路径" value="_local_" autocomplete="off" class="layui-input">
                                    </div>

                                    <div class="layui-input-inline">
                                        <button class="layui-btn layui-btn-warm del-stp" ly-build="_domain_"
                                            type="button">删除</button>
                                        <button class="layui-btn" lay-submit ly-build="_domain_"
                                            lay-filter="saveit">更新</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <hr class="layui-bg-blue">

                    <div id="news-bind">
                        <form class="layui-form" action="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">静态绑定</label>
                                <div class="layui-input-inline" style="width: 25%;">
                                    <input type="text" name="domapass" id="new-domain" required lay-verify="required"
                                        placeholder="静态访问路径" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-input-inline" style="width: 45%;">
                                    <input type="text" name="localpass" id="new-local" required lay-verify="required"
                                        placeholder="本地文件路径" autocomplete="off" class="layui-input">
                                </div>

                                <div class="layui-input-inline">
                                    <button class="layui-btn layui-btn-disabled" type="button">删除</button>
                                    <button class="layui-btn layui-btn-normal" lay-submit
                                        lay-filter="saveit">新增</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>

                <!-- 静态文件路径绑定 -->
            </div>
            <div class="layui-tab-item">
                <!-- 向我捐赠 -->

                <div class="layui-container">
                    <div style="text-align: center;">
                        <img src="http://pan.wwsg18.com/index.php?user/publicLink&fid=9b162arokDAt-J40ihcbQihTS2Fvdk4aEBmhemJJxeF04OK2Y6Vxj_IAyzDnwIaQ-f4p5PZi4XdNJlCXgPvD_KA6H8aFc5cMgGphwN94nXFefHz8Q6VvRnXG_3XZ4J5wjawaMC0Vb20&file_name=/alipay.jpg"
                            alt="alipay.jpg" style="width: 260px;height:auto;" title="支付宝捐赠给我">
                        <img src="http://pan.wwsg18.com/index.php?user/publicLink&fid=da21Iz9OAoae-vRSVzXWsf2XlJkCKRGnCroOfD1W1fm5w8WoVBZJg52rvZoBD6ronzC7cIyTxG4iKdqEa0GZd0HC_eUZMJgx48uUc8KpRi_EyLUhYN24cxPeddUcPROyKDb7eos32Po&file_name=/wechat.jpg"
                            alt="wechat.jpg" style="width: 260px;height:auto;" title="微信捐赠给我">
                    </div>
                    <hr class="layui-bg-green">
                    <div style="font-size: 20px;">
                        本人高中生：做开源有两年了。这两年里的服务器，域名费用都是自己从生活费中积攒出来的（父母也有过支持）
                        从头到尾一直没有开发过任何收费的功能（后期会推出）如果各位开发者大佬们觉得我的项目还不错，可以支持我一下，
                        一顿饭、一瓶水都行。谢谢大家了！再次感谢大家愿意使用我开发的项目！
                    </div><br />
                    <blockquote class="layui-elem-quote">
                        同时希望各位大佬能为我的项目点上一个 Star 谢谢！
                        <a href="https://gitee.com/mrxzx" target="_blank">Git@OSC</a>
                    </blockquote>
                </div>


                <!-- 向我捐赠 -->
            </div>
        </div>
    </div>

    <script src="https://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script>
    <script src="https://open.wwsg18.com/openres/editormd/editormd.min.js"></script>
    <script src="https://www.layuicdn.com/layui-v2.5.6/layui.js"></script>

    <script type="text/javascript">
        var hisMark = "";
        layui.use(['element', 'form', 'layer'], function () {
            var element = layui.element;
            var form = layui.form;
            var layer = layui.layer;

            var editor = editormd("index-editor", {
                width: "100%",
                height: "84%",
                path: "https://open.wwsg18.com/openres/editormd/lib/",

                emoji: true,
                saveHTMLToTextarea: true
            });

            // 初始化数据

            $.get('/exaster/api/setting?which=feedback-api', function (res) {
                var html = "";
                if (res.data == '0') {
                    html += '<option value="0" id="close-fa" selected>关闭</option>';
                    html += '<option value="1" id="close-fa">开启</option>';
                } else {
                    html += '<option value="0" id="close-fa">关闭</option>';
                    html += '<option value="1" id="close-fa" selected>开启</option>';
                }
                $('#feedback-select').append(html);
                form.render('select');
            });

            $.get('/exaster/api/setting?which=now-idxp', function (res) {
                $('#now-idxp').val('当前接管权：' + res.data);
                if (res.data == '系统拓展包') {
                    $('#getIdxp').addClass('layui-btn-disabled');
                    $('#getIdxp').attr('title', '本插件已接管主页！');
                }
            });

            // 初始化数据

            $('#getIdxp').click(function () {
                if (!$(this).hasClass('layui-btn-disabled')) {
                    $.get('/exaster/api/setting?which=now-idxp&do=apply', function (res) {
                        if (res.data == 'OK') {
                            layer.msg("申请信息已发送给最高管理员！");
                        }
                    });
                }
            });

            form.on('select(feedback-api)', function (data) {
                $.get('/exaster/api/setting?which=feedback-api&status=' + data.value, function (
                    res) {});
            });

            // 每过二十秒将自动对数据进行更新
            setInterval(() => {

                var newMark = editor.getMarkdown();
                if (newMark != hisMark) {
                    hisMark = newMark;
                    $.post('/exaster/api/markdown?which=index', {
                        context: editor.getMarkdown()
                    }, function (res) {
                        if (res.data == 'OK') {
                            console.log("自动保存完毕！");
                        }
                    });
                }

            }, 6 * 1000);

            // 静态绑定数据初始化
            $.get("/exaster/api/statip?do=get", function (res) {
                var list = res.data;
                for (var key in list) {
                    var template = $("#binded-tpl").html();
                    template = template.replace(/_domain_/g, key);
                    template = template.replace(/_local_/g, list[key]);
                    $("#binded").append(template);
                }
            });

            // 静态绑定操作
            $(document).on("click", ".del-stp", function () {
                var builder = $(this).attr("ly-build");
                if (builder != undefined) {
                    $.get("/exaster/api/statip?do=del&key=" + builder, function (res) {
                        $("#lye-" + builder).remove();
                    });
                } else {
                    layer.msg("未知的操作目标！");
                }
            });

            form.on('submit(saveit)', function (data) {
                var builder = $(this).attr("ly-build");

                var skey = data.field.domapass;
                var sval = data.field.localpass;


                $.get("/exaster/api/statip?do=set&key=" + skey + "&val=" + sval, function (res) {
                    if (builder == undefined) {
                        var template = $("#binded-tpl").html();
                        template = template.replace(/_domain_/g, skey);
                        template = template.replace(/_local_/g, sval);
                        $("#binded").append(template);

                        $("#new-local").html("");
                        $("#new-domain").html("");
                    }
                });

                return false;
            });

        });
    </script>
</body>

</html>